package com.itheima.mail;

import com.alibaba.fastjson.JSONObject;
import com.itheima.util.MailUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

import java.util.Map;

public class MyListener implements MessageListener {
    @Override
    public void onMessage(Message message) {
        String msg = new String(message.getBody());
        System.out.println(msg);

        Map map = JSONObject.parseObject(msg, Map.class);

        String to = String.valueOf(map.get("to"));
        String subject = String.valueOf(map.get("subject"));
        String content = String.valueOf(map.get("content"));

        System.out.println(to+"||"+subject+"||"+content);

        try {
            MailUtil.sendMsg(to, subject, content);
            System.out.println("发送成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
